\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q: When linking my program with
\b MallocDebug
\b0 , I get the error message\
\
\f1\fs24 failed on vm_allocate
\f0\fs28 \
\
in the console when I tried to allocate 43 MB. However, if I relink the exact same program without the
\b MallocDebug
\b0 library, it runs fine. Why?\
\
Q: When linking in
\b MallocDebug
\b0 , I noticed that my program VSIZE (using
\b ps -ux
\b0 ) which was 2MB without
\b MallocDebug
\b0 , would start out way high—well over 20MB. Why?\
\
A:
\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 The problem is that
\b MallocDebug
\b0 requires all of the memory to be allocated contiguously, which means that it must guess how much the program might need and allocate all of that at once at
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 the
\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 beginning The current gue
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 s
\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 timate is 40
\b0 , you can only ask for a total of 40 MB over the life of your program. After you cross that barrier, it fails. It doesn't matter if you have freed any or all of the memory you have previously asked for. The indicative error message is :
\f1\fs24 "failed on vm_allocate"
\f0\fs28 when you try to use
\b malloc()
\b0 ,
\b calloc()
\b0 ,
\b
\b0 or
\b realloc()
\b0 . \
\
There is no workaround other than running your program without using
\b MallocDebug
\b0 . \
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 Note also that